//
//    Tokaplot
//    https://code.google.com/p/tokaplot/
//
//    License: GPL v3
//    https://code.google.com/p/tokaplot/wiki/License
//
//    This file is part of Tokaplot.
//
//    Tokaplot is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    Tokaplot is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with Tokaplot.  If not, see <http://www.gnu.org/licenses/>
//

package com.tokaplot;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

//import android.util.Log;

public class TokaplotCommon extends BroadcastReceiver
{	
	//private static final String TAG = "Tokaplot";
	
	@Override
	public void onReceive(Context context, Intent intent) { 
	    
        final String action = intent.getAction();
	    if (TokaplotService.ACTION_APPWIDGET_CONFIG.equals(action)) { 
	    	
	    	WidgetInfo wInfo = new WidgetInfo(intent);
	    	
	    	// Create configuration intent
	    	Intent widgetConfigIntent = new Intent(context, TokaplotService.class);	    	
	    	widgetConfigIntent.putExtra(TokaplotService.EXTRA_APPWIDGET_FLAGS, TokaplotService.ACTION_WIDGET_CONFIG);
	    	wInfo.setIntentWithInfo(widgetConfigIntent);
			
	    	// Configure widget thread
	    	context.startService(widgetConfigIntent);
	    	
	    } else if (TokaplotService.ACTION_APPWIDGET_RESET.equals(action)) {
	    	
	    	// Create reset intent
	    	Intent widgetResetIntent = new Intent(context, TokaplotService.class);	    	
	    	widgetResetIntent.putExtra(TokaplotService.EXTRA_APPWIDGET_FLAGS, TokaplotService.ACTION_WIDGET_RESET);
			
	    	// Configure widget thread
	    	context.startService(widgetResetIntent);
	    	
	    } else if (TokaplotService.ACTION_APPWIDGET_LOCK.equals(action)) { 
	    	
	    	// Create reset intent
	    	Intent widgetLockIntent = new Intent(context, TokaplotService.class);	    	
	    	widgetLockIntent.putExtra(TokaplotService.EXTRA_APPWIDGET_FLAGS, TokaplotService.ACTION_WIDGET_LOCK);
			
	    	// Configure widget thread
	    	context.startService(widgetLockIntent);
	    	
	    } else if (TokaplotService.ACTION_APPWIDGET_UNLOCK.equals(action)) { 
	    	
	    	// Create reset intent
	    	Intent widgetUnlockIntent = new Intent(context, TokaplotService.class);	    	
	    	widgetUnlockIntent.putExtra(TokaplotService.EXTRA_APPWIDGET_FLAGS, TokaplotService.ACTION_WIDGET_UNLOCK);
			
	    	// Configure widget thread
	    	context.startService(widgetUnlockIntent);
	    	
	    } else if (TokaplotService.ACTION_APPWIDGET_PAUSE.equals(action)) { 
	    	
	    	// Create reset intent
	    	Intent widgetLockIntent = new Intent(context, TokaplotService.class);	    	
	    	widgetLockIntent.putExtra(TokaplotService.EXTRA_APPWIDGET_FLAGS, TokaplotService.ACTION_WIDGET_PAUSE);
			
	    	// Configure widget thread
	    	context.startService(widgetLockIntent);
	    	
	    } else if (TokaplotService.ACTION_APPWIDGET_RESUME.equals(action)) { 
	    	
	    	// Create reset intent
	    	Intent widgetUnlockIntent = new Intent(context, TokaplotService.class);	    	
	    	widgetUnlockIntent.putExtra(TokaplotService.EXTRA_APPWIDGET_FLAGS, TokaplotService.ACTION_WIDGET_RESUME);
			
	    	// Configure widget thread
	    	context.startService(widgetUnlockIntent);
	    }
	}
}